Skip to content

fix(libc): map ELOOP for directory opens - #1365

Closed
MarcZX10 wants to merge 1 commit into
boykopovar:mainfrom
MarcZX10:fix/libc-opendir-eloop
Closed

MarcZX10 wants to merge 1 commit into
boykopovar:mainfrom
MarcZX10:fix/libc-opendir-eloop

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Maps native ELOOP to guest errno 62 in the libc directory error converter, so opendir reports a symlink loop with the guest error instead of generic EIO. Adds a POSIX-only self-referential symlink regression case to guest_directory. On Linux, built guest_directory_tests, guest_directory_entry_tests, and guest_working_directory_tests; guest_directory, guest_directory_entries, and guest_working_directory each passed three repetitions. The conventions check and git diff --check passed. Windows symlink behavior was not tested; the regression case is excluded on Windows.

@github-actions github-actions Bot added the libc label Oct 8, 2026

@Dextroid17 Dextroid17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built and ran it, with a bisect, and cross-checked the value against the codebase's own table rather than only against the test.

Linux (CachyOS, GCC, Release):

cmake --build build --target guest_directory_tests --parallel 16
ctest -R ^guest_directory$                       →  1/1 Passed

Mutation check — the parent's Directory.cpp with your test kept:

pr-1365   (ELOOP mapped):  1/1 Passed
pr-1365^  (no ELOOP case): Failed

The value is corroborated twice over. 62 is not an arbitrary choice and not the host's:

  • core/libs/prx/libkernel/KernelErrors.hpp:69 defines SCE_KERNEL_ERROR_ELOOP = SceKernelError(62), i.e. 0x8002003E — the canonical constant, matching the 63 your neighbour ENAMETOOLONG already uses.
  • core/libs/prx/libc/src/General.cpp:77 already maps too_many_symbolic_link_levels → 62 for the std::error_code path that chdir/getcwd use. So the errno-based switch in Directory.cpp was the inconsistent twin, and this change makes the two agree on the guest ABI value instead of introducing a new one.

That second point is also why the change is needed rather than cosmetic: Linux's own ELOOP is 40 and the guest's is 62, so a title that opens a looping symlink had a real chance of seeing the host number. Our errno values are the FreeBSD/PS5 numbering, and the test pins the guest's.

The test is deterministic, which is the right way to test an errno. A self-referential symlink (create_symlink("symlink-loop", symlinkLoop)) loops on every Linux, so it cannot race or depend on privileges the way a chain of symlinks could; it is #ifndef _WIN32-guarded and removed afterwards. I also checked for a second copy of this mapping to fix: there is only the one in General.cpp, and it already had the case, so nothing else needs the same edit.

This is a comment, not an approval — I have no merge rights here.

Written with AI assistance.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Same as #1336, for opendir and a symlink loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants